﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class BackManage_comment : System.Web.UI.Page
{
    BLL.Business.CommentBLL commBLL = new BLL.Business.CommentBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindData();
        }
    }
    public void BindData()
    {
        try
        {
            DataSet ds = new DataSet();
            ds = commBLL.SelectAll();
            if ((ds == null) ||
                   (ds.Tables.Count == 0) ||
                   (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0))
            {
                return;
            }
            else
            {
                this.commentList.DataSource = ds;
                this.commentList.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
        }
    }
    protected void orderList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "deleteComm")
        {
            try
            {
                int commId = Int32.Parse(e.CommandArgument.ToString());
                if (commBLL.Delete(commId))
                {
                    BindData();
                }
                else
                {
                    Response.Write("<script>alert('删除过程出现错误！')</script>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
            }
        }
        else if (e.CommandName == "selectComm")
        {
            try
            {
                this.panel1.Visible = true;
                int commId = Int32.Parse(e.CommandArgument.ToString());
                DataSet ds = new DataSet();
                ds = commBLL.SelectByCommentId(commId);
                if ((ds == null) ||
                   (ds.Tables.Count == 0) ||
                   (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0))
                {
                    return;
                }
                else
                {
                    this.Detailtext.Text = ds.Tables[0].Rows[0]["Comm_Detailtext"].ToString();
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
            }
        }
        else
        {
            return;
        }
    }
}
